﻿using SilverlightStudentManager.StudentServiceReference;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FluentValidation;

namespace SilverlightStudentManager.Validators
{
    public class InformationValidator : AbstractValidator<Infomation>
    {
        public InformationValidator()
        {
            RuleFor(x => x.FirstName).NotEmpty()      
                .WithMessage("Input Your Firs Name");
            
            RuleFor(x => x.LastName).NotEmpty()
                .WithMessage("Input Your Last Name");

            RuleFor(x => x.Birthday)
                .Must(BeAValidDateOfBirth)
                .WithMessage("Must be within 100 years of today.");

            RuleFor(x => x.Phone).Matches("^[0-9]{0,11}$")
            .WithMessage("A valid Phone is required. (0-9)");

        }

        private bool BeAValidDateOfBirth(DateTime? dateOfBirth)
        {
            if (dateOfBirth == null) return false;
            if (dateOfBirth.Value > DateTime.Today || dateOfBirth < DateTime.Today.AddYears(-100))
                return false;
            return true;
        }
    }
}
